package com.hnkywl.sts.webservice.zjg.impl;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hnkywl.sts.dao.xsgl.ShjDao;
import com.hnkywl.sts.entity.jggl.Ckd;
import com.hnkywl.sts.entity.jggl.Jgd;
import com.hnkywl.sts.entity.jggl.Jgdmx;
import com.hnkywl.sts.entity.organ.Ck;
import com.hnkywl.sts.entity.organ.Gsjg;
import com.hnkywl.sts.entity.sys.Gg;
import com.hnkywl.sts.entity.xsgl.Kh;
import com.hnkywl.sts.service.base.SortService;
import com.hnkywl.sts.service.base.WebserviceLogService;
import com.hnkywl.sts.service.jggl.CkdService;
import com.hnkywl.sts.service.jggl.JgdService;
import com.hnkywl.sts.service.kcgl.SskcService;
import com.hnkywl.sts.service.organ.CkService;
import com.hnkywl.sts.service.organ.GsjgService;
import com.hnkywl.sts.service.sys.WzbmService;
import com.hnkywl.sts.service.xsgl.KhService;
import com.hnkywl.sts.webservice.zjg.IProcessAllocation;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: SDE08
 * Date: 14-3-13
 * Time: 下午3:40
 * To change this template use File | Settings | File Templates.
 */
@Service
public class ProcessAllocationBackService implements IProcessAllocation, ApplicationContextAware {
    private ApplicationContext applicationContext;

    //  保供合同service
    private WzbmService wzbmService;
    private JgdService jgdService;
    private WebserviceLogService webserviceLogService;
    private KhService khService;
    private SortService sortService;
    private CkService ckService;
    private CkdService ckdService;
    private GsjgService gsjgService;
    private SskcService sskcService;
    private ShjDao shjDao;


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
        wzbmService = (WzbmService) applicationContext.getBean("wzbmService");
        jgdService = (JgdService) applicationContext.getBean("jgdService");
        webserviceLogService = (WebserviceLogService) applicationContext.getBean("webserviceLogService");
    }

    @Override
    public String processAllocationResponse(String json, String serialNumber) {
        StringBuffer sb = new StringBuffer();
        String jgdh = "";
        try {
            //第一步处理序列号
            sortService.checkSerialNumber(serialNumber, "processAllocationResponse");
            //第二步验证json主要信息
            Map<String, Object> resultMap = this.validateJson(json);
            //第三步验证json的物资明细信息
            List<Map> itemList = this.compareMaps(resultMap);
            //第四步根据type信息判断是调出还是调入
            jgdh = (String) resultMap.get("materialProdNo");//加工单号
            String warehouseBillNo = (String) resultMap.get("warehouseBillNo");//出入库单号
            Jgd jgd = this.findJgdByJgdh(jgdh);//加工单
            String type = (String) resultMap.get("type"); //出入库标志
            switch (Integer.parseInt(type)) {
                case 1:
                    //调出方法
                    this.processOutMethod(itemList, jgd, warehouseBillNo);
                    sb.append("{\"code\":\"0\",\"message\":\"成功！\",\"materialProdNo\":\"" + jgdh + "\"}");
                    break;
                case 2:
                    //调入方法
                    this.processInMethod(itemList, jgd, warehouseBillNo);
                    sb.append("{\"code\":\"0\",\"message\":\"成功！\",\"materialProdNo\":\"" + jgdh + "\"}");
                    break;
                default:
                    sb.append("{\"code\":\"1\",\"message\":\"传入的type值为非1非2的不合法参数请核实信息！\",\"materialProdNo\":\"" + jgdh + "\"}");
            }
        } catch (Exception e) {
            sb.append("{\"code\":\"1\",\"message\":\"" + e.getMessage() + "\",\"materialProdNo\":\"" + jgdh + "\"}");
        }
        webserviceLogService.saveClientLog(
                ProcessAllocationBackService.class.getName(),
                "processAllocationResponse",
                json,
                sb.toString(),
                null,
                ""
        );
        return sb.toString();
    }

    /**
     * 根据加工单号查询加工单
     *
     * @param jgdh
     * @return
     */
    private Jgd findJgdByJgdh(String jgdh) throws RuntimeException {
        Jgd jgd = jgdService.findByJgdh(jgdh);
        if (jgd == null || jgd.getId() == null)
            throw new RuntimeException("传入的加工单号未找到相应的加工单，请核实信息！");
        return jgd;
    }

    /**
     * 检验json主信息
     *
     * @param json
     * @return
     * @throws RuntimeException
     */
    public Map<String, Object> validateJson(String json) throws RuntimeException {
        if (json == null)
            throw new RuntimeException("传入的json为空，请核实信息！");
        Gson gson = new Gson();
        //如果json不为空校验jgdh和type
        Map<String, Object> resultMap = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
        }.getType());
        if (resultMap.get("materialProdNo") == null || "".equals((String) resultMap.get("materialProdNo")))
            throw new RuntimeException("传入的materialProdNo为空");
//        if (resultMap.get("warehouseBillNo") == null || "".equals((String) resultMap.get("warehouseBillNo")))
//            throw new RuntimeException("传入的warehouseBillNo为空");
        if (resultMap.get("type") == null || "".equals((String) resultMap.get("type")))
            throw new RuntimeException("传入的type为空");
        return resultMap;
    }

    /**
     * 加工调出方法
     */
    private void processOutMethod(List<Map> itemList, Jgd jgd, String warehouseBillNo) throws RuntimeException {
        List<Jgdmx> jgdmxList = jgd.getJgdmxList();
        if (jgdmxList == null || jgdmxList.size() == 0)
            throw new RuntimeException("该加工单的加工单明细为空！");
        for (Map item : itemList) {
            String productCode = (String) item.get("productCode");
            String specCode = (String) item.get("specCode");
            String materialCode = (String) item.get("materialCode");
            String number = (String) item.get("number");
            String weight = (String) item.get("weight");
            List<Gg> ggList = wzbmService.findWzbmByPmCzCode(productCode, specCode, materialCode);
            this.validateKhSl(jgdmxList, ggList, weight, number);
            a:
            for (Jgdmx jgdmx : jgdmxList) {
                b:
                for (Gg gg : ggList) {
                    if (jgdmx.getJtwz().getId().equals(gg.getId()) && "0".equals(jgdmx.getZt())) {
                        jgdmx.setJg_sbsl(Double.valueOf(number) + jgdmx.getJg_sbsl());
                        jgdmx.setJg_sbzl(Double.valueOf(weight) + jgdmx.getJg_sbzl());
                        Ckd ckd = new Ckd();
                        ckd.setJgdmx(jgdmx);
                        ckd.setJgsl(Double.valueOf(number));
                        ckd.setJgzl(Double.valueOf(weight));
                        ckd.setWarehousebillno(warehouseBillNo);
                        ckd.setCkd_tz(0);
                        ckd.setSftzd(false);
                        ckdService.saveCkd(ckd);
                        //减去相应卡号的数量
                        Kh kh = jgdmx.getKh();
                        kh.setKkdsl(kh.getKkdsl() + jgdmx.getSbzl() - Double.valueOf(weight));
                        kh.setSl(kh.getSl() - Double.valueOf(weight));
                        kh.setJs(kh.getJs() - Integer.parseInt(number));
                        khService.save(kh);
                        break b;
                    }
                }
            }
            jgd.setYck(true);
            this.jgdService.update(jgd);
        }
    }


    /**
     * 加工调入方法
     *
     * @param itemList
     * @param jgd
     * @throws RuntimeException
     */
    private void processInMethod(List<Map> itemList, Jgd jgd, String warehouseBillNo) throws RuntimeException {
        List<Jgdmx> jgdmxList = jgd.getJgdmxList();
        if (jgdmxList == null || jgdmxList.size() == 0)
            throw new RuntimeException("该加工单的加工单明细为空！");

        //判断是否为冲销
        boolean cx = Double.valueOf((String) itemList.get(0).get("weight")) < 0;
        if (cx) {
            processInCancel(itemList, jgd, warehouseBillNo);
        } else {
            processInConfirm(itemList, jgd, warehouseBillNo);
        }
    }

    private void processInCancel(List<Map> itemList, Jgd jgd, String warehouseBillNo) {
        for (Jgdmx jgdmx : jgd.getJgdmxList()) {
            if (jgdmx.getCcNO() != null && jgdmx.getCcNO().equals(warehouseBillNo)) {
                Kh kh = jgdmx.getKh();
                //判断是否已经出库
                if (!kh.getCshsl().equals( kh.getSl())) {
                    throw new RuntimeException("货物已经出库，无法冲销！");
                }
                jgdService.cxJgdmx(jgdmx);
            }
        }
    }

    private void processInConfirm(List<Map> itemList, Jgd jgd, String warehouseBillNo) {
        Double zweight = this.countFromMap(itemList);//加工调入的总重量；
        Double zwsdj = this.countWsdj(jgd.getJgdmxList());//计算总的无税单价；
        for (Map item : itemList) {
            String productCode = (String) item.get("productCode");
            String specCode = (String) item.get("specCode");
            String materialCode = (String) item.get("materialCode");
            String orginCode = (String) item.get("orginCode");
            String number = (String) item.get("number");
            String weight = (String) item.get("weight");
            String sku = (String) item.get("sku");
            String warehouseCode=(String) item.get("warehouseCode");
            Ck ck = ckService.findCkByBh(warehouseCode);
            List<Gg> ggList = wzbmService.findWzbmByPmCzCode(productCode, specCode, materialCode);
            //生成新的加工单明细和新的卡号
            Kh kh = khService.createKhByJgdmxs(ck, ggList.get(0), orginCode, jgd.getJgdmxList(), number, weight, zweight, zwsdj, sku);
            jgdService.createByKh(kh, jgd, number, sku,warehouseBillNo);
            jgd.setYrk(true);
            jgdService.update(jgd);
            shjDao.executeShj(kh.getId());
        }
    }

    /**
     * 检查调出卡号的数量以免造成负库存
     *
     * @param jgdmxList
     * @param ggList
     * @param weight
     * @param number
     * @throws RuntimeException
     */
    private void validateKhSl(List<Jgdmx> jgdmxList, List<Gg> ggList, String weight, String number) throws RuntimeException {
        for (Jgdmx jgdmx : jgdmxList) {
            for (Gg gg : ggList) {
                if (jgdmx.getJtwz() == null)
                    throw new RuntimeException("此加工单调出单据未关联具体物资！该加工单明细的ID为" + jgdmx.getId());
                if (jgdmx.getJtwz().getId().equals(gg.getId()) && "0".equals(jgdmx.getZt())) {
                    Kh kh = jgdmx.getKh();
                    if (kh == null)
                        throw new RuntimeException("此加工单调出单据未关联卡号！该加工单明细的ID为：" + jgdmx.getId());
                    if (kh.getKkdsl() + jgdmx.getSbzl() - Double.valueOf(weight) < 0)
                        throw new RuntimeException(kh.getKhbm() + "库存可开单数量不足，请重新定申报数量");
                    if (kh.getSl() - Double.valueOf(weight) < 0)
                        throw new RuntimeException(kh.getKhbm() + "库存数量不足，请重新定申报数量");
                    if (kh.getJs() - Integer.parseInt(number) < 0)
                        throw new RuntimeException(kh.getKhbm() + "库存件数不足，请重新定申报件数");
                }
            }
        }
    }


    private List<Map> compareMaps(Map<String, Object> resultMap) throws RuntimeException {
        List<Map> itemList = (List<Map>) resultMap.get("items");
        if (itemList == null || itemList.size() == 0)
            throw new RuntimeException("传入items的内容为空");
        int i = 1;
        for (Map item : itemList) {
//            if (item.get("weight") == null || Double.valueOf((String) item.get("weight")) <= 0)
//                throw new RuntimeException("第" + i + "物资重量不能为空或者小于0");
            if (item.get("productCode") == null)
                throw new RuntimeException("第" + i + "物资品名编号不能为空");
//            if (item.get("number") == null || Integer.parseInt((String) item.get("number")) <= 0)
//                throw new RuntimeException("第" + i + "物资数量不能为空或者小于0");
            if (item.get("warehouseCode") == null)
                throw new RuntimeException("第" + i + "物资仓库编号不能为空");
            if (item.get("specCode") == null)
                throw new RuntimeException("第" + i + "物资规格编号不能为空");
            if (item.get("warehouseName") == null)
                throw new RuntimeException("第" + i + "物资仓库名称不能为空");
            if (item.get("specName") == null)
                throw new RuntimeException("第" + i + "物资规格名称不能为空");
            if (item.get("productName") == null)
                throw new RuntimeException("第" + i + "物资品名名称不能为空");
            Ck ck = ckService.findCkByBh((String) item.get("warehouseCode"));
            if (ck == null || ck.getId() == null)
                throw new RuntimeException("第" + i + "个物资根据传入的参数未查到关联仓库请核实信息或申请添加！");
            List<Gg> ggList = wzbmService.findWzbmByPmCzCode((String) item.get("productCode"), (String) item.get("specCode"), (String) item.get("materialCode"));
            if (ggList == null || ggList.size() <= 0)
                throw new RuntimeException("第" + i + "个物资根据传入的参数未查到关联物资请核实信息或申请添加！");
            i++;
        }
        return itemList;
    }

    private Double countFromMap(List<Map> itemList) {
        Double count = 0d;
        for (Map item : itemList) {
            count += Double.valueOf((String) item.get("weight"));
        }
        return count;
    }

    private Double countWsdj(List<Jgdmx> jgdmxList) throws RuntimeException {
        Double zwsdj = 0d;
        for (Jgdmx jgdmx : jgdmxList) {
            if (jgdmx.getJg_sbzl() == 0)
                throw new RuntimeException("加工重量为空！会造成卡号无税单价为0！");
            zwsdj += jgdmx.getJg_sbzl() * jgdmx.getKh().getWsdj();
        }
        return zwsdj;
    }

    @Override
    public String processFinishResponse(String json) {
        Gson gson = new Gson();
        StringBuffer sb = new StringBuffer();
        if (json != null) {
            Map<String, Object> resultMap = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
            }.getType());
            String jgdh = (String) resultMap.get("materialProdNo"); //加工单号
            String remark = (String) resultMap.get("remark"); //备注
            Jgd jgd = jgdService.findByJgdh(jgdh); //根据单号找到加工单
            if (jgd != null) {
                //改变加工单状态
                jgd.setBz(remark);
                jgd.setZt(2);
                jgdService.update(jgd);
                sb.append("{\"code\":\"0\",\"message\":\"加工完结成功\",\"materialProdNo\":\"" + jgdh + "\"}");
            } else
                sb.append("{\"code\":\"1\",\"message\":\"未查询到此加工单\",\"materialProdNo\":\"" + jgdh + "\"}");
        } else
            sb.append("{\"code\":\"1\",\"message\":\"传入参数为空\",\"materialProdNo\":\"\"}");
        webserviceLogService.saveClientLog(
                ProcessAllocationBackService.class.getName(),
                "processFinishResponse",
                json,
                sb.toString(),
                null,
                ""
        );
        return sb.toString();
    }

    @Override
    public String processBuyerInfoResponse(String json) {
        Gson gson = new Gson();
        StringBuffer sb = new StringBuffer();
        if (json != null) {
            Map<String, Object> resultMap = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
            }.getType());
            try {
                Gsjg gsjg = this.valitBuyerInfo(resultMap);
                String pageNo = (String) resultMap.get("pageNo"); //查询页号
                String pageSize = (String) resultMap.get("pageSize");//每页获取的条数
                String name = (String) resultMap.get("name"); //物资名称
                String standardMode = (String) resultMap.get("standardMode");//规格型号
                String callJson = sskcService.createJsonFromInfo(name, standardMode, gsjg, pageNo, pageSize);
                sb.append(callJson);
            } catch (Exception e) {
                sb.append("{\"code\":\"1\",\"message\":\"" + e.getMessage() + "\"}");
            }
        } else
            sb.append("{\"code\":\"1\",\"message\":\"传入参数为空\"}");
        webserviceLogService.saveClientLog(
                ProcessAllocationBackService.class.getName(),
                "processBuyerInfoResponse",
                json,
                sb.toString(),
                null,
                ""
        );
        return sb.toString();
    }

    private Gsjg valitBuyerInfo(Map<String, Object> resultMap) throws Exception {
        if (resultMap.get("memberCode") == null || "".equals((String) resultMap.get("memberCode")))
            throw new RuntimeException("传入的memberCode为空");
        if (resultMap.get("pageNo") == null || "".equals((String) resultMap.get("pageNo")))
            throw new RuntimeException("传入的pageNo为空");
        if (resultMap.get("pageSize") == null || "".equals((String) resultMap.get("pageSize")))
            throw new RuntimeException("传入的pageSize为空");
        Gsjg gsjg = gsjgService.findGsjgByCode((String) resultMap.get("memberCode"));
        if (gsjg == null || gsjg.getId() == null)
            throw new RuntimeException("根据传入的memberCode未查询到对应的商户信息，请核对!");
        return gsjg;
    }

    @Override
    public String processWriteOffResponse(String json, String serialNumber) {
        StringBuffer sb = new StringBuffer();
        String jgdh = "";
        try {
            //第一步处理序列号
            sortService.checkSerialNumber(serialNumber, "processWriteOffResponse");
            //第二步验证json主要信息
            Map<String, Object> resultMap = this.validateWriteOffJson(json);
            jgdh = (String) resultMap.get("materialProdNo");// 加工单号
            String warehouseBillNo = (String) resultMap.get("offWarehouseNo");// 出入库单号
            String cxdh = (String) resultMap.get("materialReversalNo");
            //第三步验证json的物资明细信息
            List<Map<String, String>> mapsList = this.procesWriteOffMap(resultMap, warehouseBillNo, cxdh);
            //第四步根据type信息判断是调出还是调入
            String type = (String) resultMap.get("type"); // 冲销类型(1:出库,2:入库)
            switch (Integer.parseInt(type)) {
                case 1:
                    //调出方法
                    this.processWriteoffMethod(mapsList);
                    sb.append("{\"code\":\"0\",\"message\":\"出库单冲销成功！\",\"materialProdNo\":\"" + jgdh + "\"}");
                    break;
                default:
                    sb.append("{\"code\":\"1\",\"message\":\"传入的type值为非1，不合法参数请核实信息！\",\"materialProdNo\":\"" + jgdh + "\"}");
            }
        } catch (Exception e) {
            sb.append("{\"code\":\"1\",\"message\":\"" + e.getMessage() + "\",\"materialProdNo\":\"" + jgdh + "\"}");
        }
        webserviceLogService.saveClientLog(
                ProcessAllocationBackService.class.getName(),
                "processWriteOffResponse",
                json,
                sb.toString(),
                null,
                ""
        );
        return sb.toString();
    }

    private void processWriteoffMethod(List<Map<String, String>> mapsList) {
        for (Map<String, String> map : mapsList) {
            Jgdmx jgdmx = jgdService.findJgdmxById(Long.parseLong(map.get("jgdmxid").toString()));
            Ckd ckd = new Ckd();
            ckd.setJgdmx(jgdmx);
            ckd.setJgsl(Double.valueOf(map.get("cxsl")));
            ckd.setJgzl(Double.valueOf(map.get("cxzl")));
            ckd.setWarehousebillno(map.get("warehouseBillNo"));
            ckd.setCxdh(map.get("cxdh"));
            ckd.setCkd_tz(1);
            ckd.setSftzd(false);
            ckdService.saveCkd(ckd);
        }
    }

    /**
     * 检验json主信息
     *
     * @param json
     * @return
     * @throws RuntimeException
     */
    public Map<String, Object> validateWriteOffJson(String json) throws RuntimeException {
        if (json == null)
            throw new RuntimeException("传入的json为空，请核实信息！");
        Gson gson = new Gson();
        //如果json不为空校验冲销单主体信息
        Map<String, Object> resultMap = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
        }.getType());
        if (resultMap.get("materialProdNo") == null || "".equals((String) resultMap.get("materialProdNo")))
            throw new RuntimeException("传入的materialProdNo为空！");
        if (resultMap.get("offWarehouseNo") == null || "".equals((String) resultMap.get("offWarehouseNo")))
            throw new RuntimeException("传入的offWarehouseNo为空！");
        if (resultMap.get("type") == null || "".equals((String) resultMap.get("type")))
            throw new RuntimeException("传入的type为空！");
        if (resultMap.get("materialReversalNo") == null || "".equals((String) resultMap.get("materialReversalNo")))
            throw new RuntimeException("传入的materialReversalNo为空！");
        return resultMap;
    }

    private List<Map<String, String>> procesWriteOffMap(Map<String, Object> resultMap, String warehouseBillNo, String cxdh) throws RuntimeException {

        List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();

        List<Map> itemList = (List<Map>) resultMap.get("items");
        if (itemList == null || itemList.size() == 0)
            throw new RuntimeException("传入items的内容为空");
        int i = 1;
        for (Map item : itemList) {
            Map<String, String> map = new HashMap<String, String>();
            if (item.get("weight") == null)
                throw new RuntimeException("第" + i + "物资重量不能为空");
            if (item.get("productCode") == null)
                throw new RuntimeException("第" + i + "物资品名编号不能为空");
            if (item.get("number") == null)
                throw new RuntimeException("第" + i + "物资数量不能为空");
            if (item.get("warehouseCode") == null)
                throw new RuntimeException("第" + i + "物资仓库编号不能为空");
            if (item.get("specCode") == null)
                throw new RuntimeException("第" + i + "物资规格编号不能为空");
            if (item.get("warehouseName") == null)
                throw new RuntimeException("第" + i + "物资仓库名称不能为空");
            if (item.get("specName") == null)
                throw new RuntimeException("第" + i + "物资规格名称不能为空");
            if (item.get("productName") == null)
                throw new RuntimeException("第" + i + "物资品名名称不能为空");
            Ck ck = ckService.findCkByBh((String) item.get("warehouseCode"));
            if (ck == null || ck.getId() == null)
                throw new RuntimeException("第" + i + "个物资根据传入的参数未查到关联仓库请核实信息或申请添加！");
            List<Gg> ggList = wzbmService.findWzbmByPmCzCode((String) item.get("productCode"), (String) item.get("specCode"), (String) item.get("materialCode"));
            Long jgdmxId = null;
            if (ggList == null || ggList.size() <= 0) {
                throw new RuntimeException("第" + i + "个物资根据传入的参数未查到关联物资请核实信息或申请添加！");
            } else {
                jgdmxId = jgdService.findJgdmxIdByContion(ck.getId(), ggList.get(0).getId(), warehouseBillNo);
                if (null == jgdmxId) {
                    throw new RuntimeException("第" + i + "个物资根据传入的信息没有查找到对应的出库单信息！");
                } else {
                    map.put("cxsl", item.get("number").toString());
                    map.put("cxzl", item.get("weight").toString());
                    map.put("jgdmxid", jgdmxId.toString());
                    map.put("warehouseBillNo", warehouseBillNo);
                    map.put("cxdh", cxdh);
                    listMap.add(map);
                }
            }
            i++;
        }
        return listMap;
    }


    @Autowired
    public void setWzbmService(WzbmService wzbmService) {
        this.wzbmService = wzbmService;
    }

    @Autowired
    public void setJgdService(JgdService jgdService) {
        this.jgdService = jgdService;
    }

    @Autowired
    public void setWebserviceLogService(WebserviceLogService webserviceLogService) {
        this.webserviceLogService = webserviceLogService;
    }

    @Autowired
    public void setKhService(KhService khService) {
        this.khService = khService;
    }

    @Autowired
    public void setSortService(SortService sortService) {
        this.sortService = sortService;
    }

    @Autowired
    public void setCkService(CkService ckService) {
        this.ckService = ckService;
    }

    @Autowired
    public void setCkdService(CkdService ckdService) {
        this.ckdService = ckdService;
    }

    @Autowired
    public void setGsjgService(GsjgService gsjgService) {
        this.gsjgService = gsjgService;
    }

    @Autowired
    public void setSskcService(SskcService sskcService) {
        this.sskcService = sskcService;
    }

    @Autowired
    public void setShjDao(ShjDao shjDao) {
        this.shjDao = shjDao;
    }
}
